import { createRouter, createWebHistory } from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import LayoutView from '../components/LayoutView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: LayoutView,
      children: [
        // 首页
        {
          path: '',
          name: 'index',
          component: () => import('../views/Index/IndexView.vue'),
          meta: { title: '首页' },
        },
        {
          path: 'productList',
          name: 'productList',
          component: () => import('../views/Product/ProductList.vue'),
          meta: { title: '产品列表' },
        },
        {
          path: 'productDetail',
          name: 'productDetail',
          component: () => import('../views/Product/ProductDetail.vue'),
          meta: { title: '产品列表' },
        },
        {
          path: 'about',
          name: 'about',
          component: () => import('../views/AboutUs/AboutView.vue'),
          meta: { title: '产品列表' },
        },
        {
          path: '/order',
          name: 'order',
          component: () => import('../views/Order/OrderView.vue'),
        },
        {
          path: '/after',
          name: 'after',
          component: () => import('../views/AfterSale/AfterSaleListView.vue'),
        },
        {
          path: '/inquiry',
          name: 'inquiry',
          component: () => import('../views/MulteInquiry/MulteInquiryView.vue'),
        },
        {
          path: '/car',
          name: 'car',
          component: () => import('../views/Car/CarView.vue'),
        },
        {
          path: '/person',
          name: 'person',
          component: () => import('../views/PersonalCenter/PersonalCenterView.vue'),
        },
        {
          path: '/myorder',
          name: 'myorder',
          component: () => import('../views/Order/MyOrderView.vue'),
        },
        {
          path: '/payOrder',
          name: 'payOrder',
          component: () => import('../views/payOrder/payOrder.vue'),
        },{
          path: '/wxPay',
          name: 'wxPay',
          component: () => import('../views/payOrder/wxPay.vue'),
        },
        {
          path: '/orderEvaluation',
          name: 'orderEvaluation',
          component: () => import('../views/Order/OrderEvaluation.vue'),
        },
      ]
    },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue'),
    // },
    {
      path: '/login',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Login/LoginView.vue'),
    },
  ],
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      // 如果存在保存的滚动位置，返回该位置（比如浏览器的前进后退操作）
      return savedPosition;
    } else {
      // 否则滚动到顶部
      return { top: 0 };
    }
  },
})

export default router
